import time

from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser
from page.front_stage.login_page import LoginPage


class AddressPage(Base):
    address_url = 'http://139.129.26.163/user.php'

    def user_center(self):  # 用户中心
        self.click((By.XPATH, '//*[@id="ECS_MEMBERZONE"]/font/a[1]'))

    def shipping_address(self):
        self.click((By.PARTIAL_LINK_TEXT, '收货地址'))

    # # id="selProvinces_0" 省
    def province(self, text):
        self.select_by_text((By.ID, 'selProvinces_0'), text)

    # id="selCities_0" 市
    def city(self, text):
        self.select_by_text((By.ID, 'selCities_0'), text)

    # id="selDistricts_0" 区
    def district(self, text):
        self.select_by_text((By.ID, 'selDistricts_0'), text)

    # name="consignee"  收件人 (By.ID,'consignee_0')
    def recipient(self, consignee):
        self.send_keys(('name', 'consignee'), consignee)

    # name="email" 邮箱
    def email(self, email):
        self.send_keys(('name', 'email'), email)

    # name="address" 收货地址
    def address(self, address):
        self.send_keys(('name', 'address'), address)

    # name="tel" 电话
    def tel(self, tel):
        self.send_keys(('name', 'tel'), tel)

    # class="bnt_blue" 删
    def delete_bnt(self):
        self.click((By.CLASS_NAME, 'bnt_blue'))

    def modify_information(self, locator, text):
        self.find_element(locator)

    # class="bnt_blue_1"  确认修改
    def revise_bnt(self):
        self.click((By.CLASS_NAME, 'bnt_blue_1'))

    # class="bnt_blue_2"  增
    def new_bnt(self):
        self.click((By.CLASS_NAME, 'bnt_blue_2'))


if __name__ == '__main__':
    browser = open_browser()
    add = AddressPage(browser)
    add.get("http://139.129.26.163/user.php")
    add.send_keys((By.NAME, 'username'), 'Ella')
    add.send_keys((By.NAME, 'password'), 'Aa123456')
    add.click((By.NAME, 'submit'))

    add.shipping_address()
    add.province('湖北省')
    add.city('武汉市')
    add.district('江夏区')

    add.recipient('Ella')
    add.clear((By.ID, 'email_0'))
    add.email('lala@qq.com')
    add.address('湖北省武汉市江夏区源码时代')
    add.tel(13113113113)
    print(add.get_attr(('name', 'consignee'), 'value'))

    add.new_bnt()

    add.delete_bnt()
    add.alter_accept()

    add.quit()
